// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.profiling;

import zombie.util.list.PZArrayUtil;

public class PerformanceProfileProbeList<Probe extends PerformanceProfileProbe> {
    final String m_prefix;
    final Probe[] layers;

    public static PerformanceProfileProbeList<PerformanceProfileProbe> construct(String prefix, int count) {
        return new PerformanceProfileProbeList<>(prefix, count, PerformanceProfileProbe.class, PerformanceProfileProbe::new);
    }

    public static <Probe extends PerformanceProfileProbe> PerformanceProfileProbeList<Probe> construct(
        String prefix, int count, Class<Probe> type, PerformanceProfileProbeList.Constructor<Probe> ctor
    ) {
        return new PerformanceProfileProbeList<>(prefix, count, type, ctor);
    }

    protected PerformanceProfileProbeList(String string, int int0, Class<Probe> _class, PerformanceProfileProbeList.Constructor<Probe> constructor) {
        this.m_prefix = string;
        this.layers = (Probe[])PZArrayUtil.newInstance(_class, int0 + 1);

        for (int int1 = 0; int1 < int0; int1++) {
            this.layers[int1] = (Probe)constructor.get(string + "_" + int1);
        }

        this.layers[int0] = (Probe)constructor.get(string + "_etc");
    }

    public int count() {
        return this.layers.length;
    }

    public Probe at(int _int) {
        return _int < this.count() ? this.layers[_int] : this.layers[this.count() - 1];
    }

    public Probe start(int _int) {
        PerformanceProfileProbe performanceProfileProbe = this.at(_int);
        performanceProfileProbe.start();
        return (Probe)performanceProfileProbe;
    }

    public interface Constructor<Probe extends PerformanceProfileProbe> {
        Probe get(String var1);
    }
}
